# This is a sample Python script.
import TaxRate
import matplotlib.pyplot as plt


def drawNormalTax():
    salaryList = []
    taxList = []
    taxList3 = []
    taxList4 = []
    for salary in range(0, 1300000, 1300):
        salaryList.append(salary / 10000)
        taxList.append(TaxRate.F1(salary) / 10000)
        taxList3.append(TaxRate.F3(salary) / 10000)
        taxList4.append(TaxRate.F4(salary) / 10000)
    # 设置图片大小（1920*1080像素）
    plt.figure(figsize=(16, 9), dpi=120)
    # 设置全局字体(STSONG，宋体)
    # my_font = matplotlib.font_manager.FontProperties(fileName="C:/WINDOWS/Fonts/STSONG.TTF")
    plt.rcParams['font.family'] = ['STSONG']
    # 设置x、y轴标注
    plt.xlabel("应纳税所得额(万元)", fontsize=18)
    plt.ylabel("税额（万元）", fontsize=18)
    # 绘制网格（不透明度=0.4）
    plt.grid(alpha=0.4)
    # 填入数据
    plt.plot(salaryList, taxList, label='综合所得')
    plt.plot(salaryList, taxList3, label='经营所得')
    plt.plot(salaryList, taxList4, label='其他所得')
    # 显示标注
    plt.legend(loc='upper left', fontsize=12)
    # 设置保存图片路径
    # plt.savefig('d:/NormalTax.png')
    # 生成图片
    plt.show()


def drawFinalBonus():
    salaryList = []
    taxSingleList = []
    taxCombineList = []
    for salary in range(0, 1300000, 1300):
        salaryList.append(salary / 10000)
        taxSingleList.append(TaxRate.F2(salary, True) / 10000)
        taxCombineList.append(TaxRate.F2(salary) / 10000)
    # 设置图片大小（1920*1080像素）
    plt.figure(figsize=(16, 9), dpi=120)
    # 设置全局字体(STSONG，宋体)
    # my_font = matplotlib.font_manager.FontProperties(fileName="C:/WINDOWS/Fonts/STSONG.TTF")
    plt.rcParams['font.family'] = ['STSONG']
    # 设置x、y轴标注
    plt.xlabel("应纳税所得额(万元)", fontsize=18)
    plt.ylabel("税额（万元）", fontsize=18)
    # 绘制网格（不透明度=0.4）
    plt.grid(alpha=0.4)
    # 填入数据
    plt.plot(salaryList, taxSingleList, label='独立计税')
    plt.plot(salaryList, taxCombineList, label='并入综合所得')
    # 显示标注
    plt.legend(loc='upper left', fontsize=12)
    # 设置保存图片路径
    # plt.savefig('d:/Sbonus.png')
    # 生成图片
    plt.show()


def drawDevidedSalary(STotal):
    interval = 1  # 绘图取点间隔
    tempTotal = STotal
    while tempTotal > 1000:
        interval = interval * 10
        tempTotal = tempTotal / 10
    unit = 1
    unitName = '（元）'
    # 扩大单位（万元、亿元）
    if STotal > 10000:
        unit = 10000
        unitName = '（万元）'
    if STotal > 100000000:
        unit = 100000000
        unitName = '（亿元）'

    # 设置图片大小（1920*1080像素）
    plt.figure(figsize=(16, 9), dpi=120)
    # 设置全局字体(STSONG，宋体)
    plt.rcParams['font.family'] = ['STSONG']
    # 用标题显示计算结果（最小值）
    plt.title(TaxRate.devideSalary(STotal), fontsize=18)

    salaryList = []
    taxList = []
    for salary in range(0, STotal, interval):
        salaryList.append(salary / unit)
        if salary <= 60000:
            tempSalary = 0
        else:
            tempSalary = salary - 60000
        taxList.append((TaxRate.F1(tempSalary) + TaxRate.F2(STotal - salary, True)) / unit)
    # 设置x、y轴标注
    plt.xlabel("综合所得部分" + unitName, fontsize=18)
    plt.ylabel("总税额" + unitName, fontsize=18)
    # 绘制网格（不透明度=0.4）
    plt.grid(alpha=0.4)
    # 填入数据
    plt.plot(salaryList, taxList)
    # 设置保存图片路径
    # plt.savefig('d:/DevidedSalary.png')
    # 生成图片
    plt.show()


def drawSomething():
    import math
    xList = []
    list2n = []
    listn2 = []
    for n in range(1, 100):
        x = float(n) / 10
        xList.append(x)
        list2n.append(math.pow(2, x))
        listn2.append(math.pow(x, 2))
    # 绘制网格（不透明度=0.4）
    plt.grid(alpha=0.4)
    # 填入数据
    plt.plot(xList, list2n, label='2^n')
    plt.plot(xList, listn2, label='n^2')
    # 显示标注
    plt.legend(loc='upper left', fontsize=12)
    # 设置保存图片路径
    # plt.savefig('d:/NormalTax.png')
    # 生成图片
    plt.show()


if __name__ == '__main__':
    drawSomething()
    drawNormalTax()
    drawFinalBonus()
    drawDevidedSalary(400000)
    drawDevidedSalary(1000000)
